package org.lalib.mediator;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.lalib.acquire.IMediator;
import org.lalib.entity.object.EFood;
import org.lalib.entity.object.EOrder;
import org.lalib.entity.object.ETable;
import org.lalib.foundation.FDataAccess;
import org.springframework.stereotype.Repository;

@Repository("mOrder")
public class MOrder extends FDataAccess<EOrder> implements IMediator {

	private static final long serialVersionUID = 1L;

	@Override
	protected Class<EOrder> getClassType() {
		return EOrder.class;
	}

	@SuppressWarnings("unchecked")
	public List<EOrder> getCurrentOrders(ETable table) {
		return getSession().createCriteria(getClassType()).add(Restrictions.eq("odendi", false)).add(Restrictions.eq("eTable", table)).list();
	}

	@SuppressWarnings("unchecked")
	public List<EOrder> getCurrentOrders(List<EFood> foods) {
		return getSession().createCriteria(getClassType()).add(Restrictions.eq("hazirlandi", false)).add(Restrictions.in("eFood", foods)).list();
	}

	@SuppressWarnings("unchecked")
	public List<EOrder> getTakenOrders(Date startDate, Date endDate) {
		return getSession().createCriteria(getClassType()).add(Restrictions.between("date", startDate, endDate))
				.add(Restrictions.eq("odendi", true)).add(Restrictions.eq("hazirlandi", true)).list();
	}
}